package com.order.controller;

import com.alibaba.fastjson.JSONObject;
import com.order.service.OrderService;
import entity.OrderEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Daft_V
 * @Date 2022/5/15 16:21
 */
@Controller
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 查询order列表接口
     *
     * @return JSONObject
     */
    @GetMapping("/orderList")
    @ResponseBody
    @PreAuthorize("hasAnyAuthority('orderList')")
    public JSONObject orderList() {
        Map<String, Object> map = new HashMap<>();
        List<OrderEntity> orderEntityList = orderService.queryOrderList();
        map.put("code", 200);
        map.put("data", orderEntityList);
        JSONObject jsonObject = new JSONObject(map);
        return jsonObject;
    }
}
